﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Adams.Shared
{
    public static class Str
    {
        public static bool IsEqual(string val1, string val2)
        {
            return string.Compare(val1, val2, StringComparison.InvariantCultureIgnoreCase) == 0;
        }

        public static string GenerateRandomString(int length)
        {
            char[] columns = new char[36];
            for(int i = 65; i < 65 + 26; i++)
            {
                columns[i - 65] = (char)i;
            }
            for(int i = 48; i <= 57; i++)
            {
                columns[26 + (i - 48)] = (char)i;
            }

            StringBuilder sb = new StringBuilder(length);
            Random rand = new Random();
            for (int i = 0; i < length; i++)
            {
                sb.Append(columns[rand.Next(36)].ToString());
            }

            return sb.ToString();
        }
    }

    public class StringComparerCaseInsensitive : IEqualityComparer<string>
    {
        #region IEqualityComparer<string> Members

        public bool Equals(string x, string y)
        {
            return string.Compare(x, y, StringComparison.InvariantCultureIgnoreCase) == 0;
        }

        public int GetHashCode(string obj)
        {
            return obj.GetHashCode();
        }

        #endregion
    }
}
